<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title data-react-helmet="true">知乎 - 有问题上知乎</title>
    <link rel="stylesheet" href="/css/bootstrap.min.css">
    <script src="/js/jquery-3.3.1.min.js"></script>
    <script src="/js/bootstrap.js"></script>
    <link rel="stylesheet" href="/css/summernote.css">
    <script src="/js/summernote.js"></script>
    <script src="/js/summernote-zh-CN.js"></script>
    <script src="/js/jquery.form.js"></script>

    <style>
        .flag {
            background: rgba(153, 185, 249, 0.57);
            border-radius: 180px;
            color: #2b669a;
            border: 0;
        }

        b {
            font-size: 18px;
        }

        #td_left {
            padding-right: 30px;
            text-align: center;
            border-right: 1px #eeeeee solid;
        }

        #td_right {
            padding-left: 30px;
            text-align: center;
        }

        body {
            background-color: #E5E5E5;
        }

        #middle {
            background-color: white;
        }

        nav {
            background-color: deepskyblue !important;
            margin-bottom: 0px !important;
        }

        .question_context {
            background-color: white !important;
            margin-top: 20px;
            padding: 15px;
        }

        #middle_div {
            padding-top: 30px !important;
        }

        img {
            width: 200px;
            height: 250px;
        }

    </style>


</head>
<body>
<div class="col-md-12" style="padding: 0">
    <nav class="navbar navbar-default" style="background-color: #2b669a">
        <div class="col-md-3"></div>
        <div class="col-md-6">
            <div class="container-fluid">
                <!-- Brand and toggle get grouped for better mobile display -->
                <div class="navbar-header">
                    <button type="button" class="navbar-toggle collapsed" data-toggle="collapse"
                            data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
                        <span class="sr-only">Toggle navigation</span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                    </button>
                    <a class="navbar-brand" href="#"><strong>知乎</strong></a>
                </div>

                <!-- Collect the nav links, forms, and other content for toggling -->
                <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                    <ul class="nav navbar-nav">
                        <li><a href="/pages/question_first.html">首页</a></li>
                        <li><a href="/pages/question_list.html">发现</a></li>
                        <li><a href="">话题</a></li>
                    </ul>
                    <div class="navbar-form navbar-left" action="/question/add" method="post">
                        <div class="form-group">
                            <input type="search" class="form-control" placeholder="母猪产后如何护理"/>
                        </div>
                        <button id="ask" type="submit" class="btn btn-default"
                                style="background-color: dodgerblue" data-toggle="modal"
                                data-target="#add_modal">提问
                        </button>

                    </div>
                    <ul class="nav navbar-nav navbar-right">
                        <li><a href="#"><span class="glyphicon glyphicon glyphicon-bell"></span> </a></li>
                        <li class="dropdown">
                            <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button"
                               aria-haspopup="true"
                               aria-expanded="false">
                                <img id="hand_image" style="width: 20px;height: 20px;border-radius: 3px" src="">
                            </a>
                            <ul class="dropdown-menu">
                                <li><a href="#"><span class="glyphicon glyphicon glyphicon-user"></span> 我的主页</a></li>
                                <li><a href="#"><span class="glyphicon glyphicon glyphicon-cog"></span> 设置</a></li>
                                <li role="separator" class="divider"></li>
                                <li><a href="#"><span class="glyphicon glyphicon glyphicon-off"></span> 退出</a></li>
                            </ul>
                        </li>
                    </ul>
                </div><!-- /.navbar-collapse -->
            </div><!-- /.container-fluid -->
        </div>
        <div class="col-md-3"></div>
    </nav>
</div>


<!-- AddAnswerModal -->
<div class="modal fade" id="add_modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog modal-lg" role="document">
        <div class="modal-content">
            <div class="modal-header">

                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title" id="myModalLabel">发布问题</h4>

            </div>
            <div class="modal-body">
                <span id="msg" style="color: red"></span>
                <form id="addquestion_form" action="/question/add" method="post">

                    <input type="text" name="title"
                           placeholder="写下你的问题准确地描述问题更容易得到解答">

                    <textarea id="summernote" name="synopsis"
                              placeholder="输入问题背景，条件等详细信息"></textarea>
                </form>
            </div>
            <div class="modal-footer">
                <button id="add_btn" type="button" class="btn btn-primary">发布问题</button>
            </div>
        </div>
    </div>
</div>

<div class="col-md-12"></div>
<div class="col-md-3"></div>
<div class="col-md-6">
    <div class="col-md-9">
        <ul class="nav nav-tabs">
            <li role="presentation" class="active"><a href="#">已关注的话题动态</a></li>
        </ul>
    </div>
    <div class="col-md-3">
        <button type="button" class="btn btn-primary">话题广场</button>
    </div>

</div>
<div class="col-md-3"></div>

<div id="middle" class="col-md-12">
    <div id="middle_div" style="height:230px;border-bottom: 2px solid #eeeeee">
        <div class="col-md-3"></div>
        <div class="col-md-6">
            <div id="flag_context" class="col-md-9">
            </div>
            <div class="col-md-3">
                <table cellspacing="0">
                    <tr>
                        <td id="td_left">
                            <p>关注者</p>
                            <p><b>2,294</b></p>
                        </td>
                        <td id="td_right">
                            <p>被浏览</p>
                            <p><b>9,805,993</b></p>
                        </td>
                    </tr>
                </table>
            </div>
        </div>
        <div class="col-md-3"></div>
    </div>
</div>

<div class="col-md-3"></div>
<div class="col-md-6">
    <div id="question_context">
    </div>
</div>
<div class="col-md-3"></div>
</body>
<script>


    $.ajax({
        url: "/user/getSession",
        dataType: "json",
        success: function (sessionUser) {
            $("#hand_image").prop("src", sessionUser.handimage)
        }
    });


    <!--显示已关注的话题-->
    $.ajax({
        url: "/topic/selectAll",
        dataType: "json",
        success: function (result) {
            var topicList = result.topicList;
            for (var i = 0; i < 4; i++) {
                var str = '<button class="flag">' + topicList[i].title + '</button>';
                $("#flag_context").append(str);
            }
        }
    });

    //提交问题
    $("#add_btn").click(function () {
        $("#add_btn").prop("disabled", true);

        $("#addquestion_form").ajaxSubmit({
            // dataType:"json",
            success: function (result) {
                if (result != null) {
                    $("#add_btn").prop("disabled", false);
                    $("#add_modal").modal("hide");
                    $("#add_modal").resetForm();
                    window.location.href = "answer_show.html?qid=" + result;
                } else {
                    $("#add_btn").prop("disabled", false);
                    $("#msg").html("提交失败~请重新提交！")
                }
            }
        })
    })
    //文本编辑器
    $("#summernote").summernote({
        height: 500,
        callbacks: {
            onImageUpload: function (files) {
                var formData = new FormData();
                formData.append('file', files[0]);
                $.ajax({
                    url: '/question/uploadImage',//后台文件上传接口
                    type: 'POST',
                    data: formData,
                    processData: false,
                    contentType: false,
                    success: function (data) {
                        $('#summernote').summernote('insertImage', data, 'img');
                    }
                });
            }
        }
    });


    <!--查询question-->
    $(function () {
        $.ajax({
            url: "/question/list",
            success: function (result) {
                var questionList = result.rows;
                for (var i = 0; i < questionList.length; i++) {
                    var questionDiv = '<div class-md-3>\n' +
                        '<img src="' + questionList[i].image + '"/>\n' +
                        '<span>' + questionList[i].title + '</span>' +
                        '<br>\n' +
                        '<span>' + questionList[i].synopsis + '</span>' +
                        '</div>'
                    $("#question_context").append(questionDiv);
                }
            }
        })
    });


</script>
</html>